Skip to contentSkip to conversation

Change in openvpn[master]: allow user to specify 'local' multiple times in config files

Openvpn-devel In review ordex (Code Review) 2 participants 28 messages Nov 15, 2023 – Jan 23, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1700055887000.I4d1c96662c5a8c750d883e3b20adde09529e2764@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/436?usp=email

to review the following change.

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

allow user to specify 'local' multiple times in config files

It is now possible to specify 'local' multiple times in a server config to let it listen on multiple sockets (address:port) of the same protocol.

Change-Id I4d1c96662c5a8c750d883e3b20adde09529e2764

---
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c

4 files changed, 171 insertions(+), 39 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/436/1

src/openvpn/init.c +5 -4
index f8dd01f..659c9e3 100644
@@ -745,7 +745,7 @@
 
     init_connection_list(c);
 
-    c->c1.link_sockets_num = 1;
+    c->c1.link_sockets_num = c->options.ce.local_list->len;
 
     do_link_socket_addr_new(c);
 
@@ -3821,8 +3821,8 @@
 
         /* init each socket with its specific port */
         link_socket_init_phase1(c->c2.link_sockets[i],
-                                c->options.ce.local,
-                                c->options.ce.local_port,
+                                c->options.ce.local_list->array[i]->local,
+                                c->options.ce.local_list->array[i]->port,
                                 c->options.ce.remote,
                                 c->options.ce.remote_port,
                                 c->c1.dns_cache,
@@ -3836,7 +3836,7 @@
 #ifdef ENABLE_DEBUG
                                 c->options.gremlin,
 #endif
-                                c->options.ce.bind_local,
+                                c->options.ce.local_list->array[i]->bind_local,
                                 c->options.ce.remote_float,
                                 &c->c1.link_socket_addrs[i],
                                 c->options.ipchange,
@@ -4978,6 +4978,7 @@
     if (dest->mode == CM_CHILD_UDP)
     {
         ASSERT(!dest->c2.link_sockets);
+        ASSERT(dest->options.ce.local_list);
 
         /* inherit buffers */
         dest->c2.buffers = src->c2.buffers;
src/openvpn/options.c +139 -28

253 lines not on this page · raw message

src/openvpn/options.h +14 -1
index 5a37316..747ed56 100644
@@ -94,14 +94,21 @@
 #error "At least one of OpenSSL or mbed TLS needs to be defined."
 #endif
 
+struct local_entry
+{
+    const char *local;
+    const char *port;
+    bool bind_local;
+};
+
 struct connection_entry
 {
+    struct local_list *local_list;
     int proto;
     sa_family_t af;
     const char *local_port;
     bool local_port_defined;
     const char *remote_port;
-    const char *local;
     const char *remote;
     bool remote_float;
     bool bind_defined;
@@ -179,6 +186,12 @@
 
 #define CONNECTION_LIST_SIZE 64
 
+struct local_list
+{
+    int len;
+    struct local_entry *array[CONNECTION_LIST_SIZE];
+};
+
 struct connection_list
 {
     int capacity;
src/openvpn/socket.c +13 -6
index 17bd263..5d9e111 100644
@@ -342,7 +342,7 @@
 void
 do_preresolve(struct context *c)
 {
-    int i;
+    int i, j;
     struct connection_list *l = c->options.connection_list;
     const unsigned int preresolve_flags = GETADDR_RESOLVE
                                           |GETADDR_UPDATE_MANAGEMENT_STATE
@@ -416,12 +416,19 @@
             }
         }
 
-        if (ce->bind_local)
+        flags |= GETADDR_PASSIVE;
+        flags &= ~GETADDR_RANDOMIZE;
+
+        for (j = 0; j < ce->local_list->len; j++)
         {
-            flags |= GETADDR_PASSIVE;
-            flags &= ~GETADDR_RANDOMIZE;
-            status = do_preresolve_host(c, ce->local, ce->local_port,
-                                        ce->af, flags);
+            struct local_entry *le = ce->local_list->array[j];
+
+            if (!le->local)
+            {
+                continue;
+            }
+
+            status = do_preresolve_host(c, le->local, le->port, ce->af, flags);
             if (status != 0)
             {
                 goto err;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

ordex has abandoned this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Abandoned
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: abandon

#3 lore raw
In reply to a message not in the archive

ordex has restored this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Restored
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: restore

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Set Ready For Review

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 2
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 24 Sep 2024 20:43:29 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: its_Giaan, ordex, plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Patch Set 2: Code-Review-1

(4 comments)

Patchset:

PS2:
Need to look into the macOS build failures.

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/d52e4152_214d8bc0 :
PS2, Line 127: "--local host|* [port] : Local host name or ip address and port. '*' can be used\n"
Some of this should move to the documentation instead.

http://gerrit.openvpn.net/c/openvpn/+/436/comment/84cfb07a_49de2180 :
PS2, Line 997: befor
"be for"?

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/cbf102c9_02a57533 :
PS2, Line 345: int i, j;
For new code please move the declaration to the actual first use. No need to stay in pre-C99 style.

Signature · 19 lines
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 2
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 25 Sep 2024 14:12:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
#6 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.

its_Giaan has uploaded a new patch set (#3) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

allow user to specify 'local' multiple times in config files

It is now possible to specify 'local' multiple times in a server config to let it listen on multiple sockets (address:port) of the same protocol.

Change-Id I4d1c96662c5a8c750d883e3b20adde09529e2764

---
M doc/man-sections/link-options.rst
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c

5 files changed, 177 insertions(+), 44 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/436/3

doc/man-sections/link-options.rst +6 -4
index ca192c3..05909ca 100644
@@ -106,10 +106,12 @@
   is not reliable. It is recommended to set tun-mtu with enough headroom
   instead.
 
---local host
-  Local host name or IP address for bind. If specified, OpenVPN will bind
-  to this address only. If unspecified, OpenVPN will bind to all
-  interfaces.
+--local host|* [port]
+  Local host name or IP address and port for bind. If specified, OpenVPN will bind
+  to this address. If unspecified, OpenVPN will bind to all interfaces.
+  '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
+  is returned by the OS). Implies --bind.
+  0.0.0.0 or :: can be used to specifically open a socket.
 
 --lport port
   Set local TCP/UDP port number or name. Cannot be used together with
src/openvpn/init.c +5 -4
index f406c0f..575b4d2 100644
@@ -742,7 +742,7 @@
 
     init_connection_list(c);
 
-    c->c1.link_sockets_num = 1;
+    c->c1.link_sockets_num = c->options.ce.local_list->len;
 
     do_link_socket_addr_new(c);
 
@@ -3859,8 +3859,8 @@
 
         /* init each socket with its specific port */
         link_socket_init_phase1(c->c2.link_sockets[i],
-                                c->options.ce.local,
-                                c->options.ce.local_port,
+                                c->options.ce.local_list->array[i]->local,
+                                c->options.ce.local_list->array[i]->port,
                                 c->options.ce.remote,
                                 c->options.ce.remote_port,
                                 c->c1.dns_cache,
@@ -3874,7 +3874,7 @@
 #ifdef ENABLE_DEBUG
                                 c->options.gremlin,
 #endif
-                                c->options.ce.bind_local,
+                                c->options.ce.local_list->array[i]->bind_local,
                                 c->options.ce.remote_float,
                                 &c->c1.link_socket_addrs[i],
                                 c->options.ipchange,
@@ -5008,6 +5008,7 @@
     if (dest->mode == CM_CHILD_UDP)
     {
         ASSERT(!dest->c2.link_sockets);
+        ASSERT(dest->options.ce.local_list);
 
         /* inherit buffers */
         dest->c2.buffers = src->c2.buffers;
src/openvpn/options.c +139 -28

253 lines not on this page · raw message

src/openvpn/options.h +14 -1
index ee39dbb..6942455 100644
@@ -94,14 +94,21 @@
 #error "At least one of OpenSSL or mbed TLS needs to be defined."
 #endif
 
+struct local_entry
+{
+    const char *local;
+    const char *port;
+    bool bind_local;
+};
+
 struct connection_entry
 {
+    struct local_list *local_list;
     int proto;
     sa_family_t af;
     const char *local_port;
     bool local_port_defined;
     const char *remote_port;
-    const char *local;
     const char *remote;
     bool remote_float;
     bool bind_defined;
@@ -179,6 +186,12 @@
 
 #define CONNECTION_LIST_SIZE 64
 
+struct local_list
+{
+    int len;
+    struct local_entry *array[CONNECTION_LIST_SIZE];
+};
+
 struct connection_list
 {
     int capacity;
src/openvpn/socket.c +13 -7
index 8677472..8051a97 100644
@@ -342,7 +342,6 @@
 void
 do_preresolve(struct context *c)
 {
-    int i;
     struct connection_list *l = c->options.connection_list;
     const unsigned int preresolve_flags = GETADDR_RESOLVE
                                           |GETADDR_UPDATE_MANAGEMENT_STATE
@@ -350,7 +349,7 @@
                                           |GETADDR_FATAL;
 
 
-    for (i = 0; i < l->len; ++i)
+    for (int i = 0; i < l->len; ++i)
     {
         int status;
         const char *remote;
@@ -416,12 +415,19 @@
             }
         }
 
-        if (ce->bind_local)
+        flags |= GETADDR_PASSIVE;
+        flags &= ~GETADDR_RANDOMIZE;
+
+        for (int j = 0; j < ce->local_list->len; j++)
         {
-            flags |= GETADDR_PASSIVE;
-            flags &= ~GETADDR_RANDOMIZE;
-            status = do_preresolve_host(c, ce->local, ce->local_port,
-                                        ce->af, flags);
+            struct local_entry *le = ce->local_list->array[j];
+
+            if (!le->local)
+            {
+                continue;
+            }
+
+            status = do_preresolve_host(c, le->local, le->port, ce->af, flags);
             if (status != 0)
             {
                 goto err;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 3
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset

#7 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, ordex, plaisthos.

its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Patch Set 3:

(3 comments)

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/e65be83d_307d5115 :
PS2, Line 127: "--local host|* [port] : Local host name or ip address and port. '*' can be used\n"

Quoted 1 line

Some of this should move to the documentation instead.

Done

http://gerrit.openvpn.net/c/openvpn/+/436/comment/e082d9e2_59ce1158 :
PS2, Line 997: befor

Quoted 1 line

"be for"?

Done

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/7a7bcf88_b92b38b3 :
PS2, Line 345: int i, j;

Quoted 1 line

For new code please move the declaration to the actual first use. No need to stay in pre-C99 style.

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 3
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: its_Giaan <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Tue, 01 Oct 2024 15:31:58 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment

#8 lore raw
In reply to a message not in the archive

Attention is currently required from: its_Giaan, ordex, plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Patch Set 5: Code-Review-1

(7 comments)

File doc/man-sections/link-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/82b9206f_257c5965 :
PS5, Line 114: 0.0.0.0 or :: can be used to specifically open a socket.
Sentence does end in the middle?

http://gerrit.openvpn.net/c/openvpn/+/436/comment/729f1acd_879715ca :
PS5, Line 117: or name
Should probably say "default TCP/UDP port number" or something like that and mention that this can be overridden by individual --local entries.

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/e215e510_be593b03 :
PS5, Line 2400: * Sanity check on daemon mode
Not sure what daemon is supposed to mean in this context?

http://gerrit.openvpn.net/c/openvpn/+/436/comment/7f064a0d_b60cd452 :
PS5, Line 3198: if (ce->proto == PROTO_UDP && ce->socks_proxy_server && !ce->local_list && !ce->local_port_defined && !ce->bind_defined)
Should use need_bind to simplify the condition.

http://gerrit.openvpn.net/c/openvpn/+/436/comment/09c9c53d_d50c5988 :
PS5, Line 3327: options_postprocess_mutate_le(struct options *o, struct local_entry *le) should maybe take o->ce as input and not o, just to make clear that it doesn't need the rest?

http://gerrit.openvpn.net/c/openvpn/+/436/comment/5052e26b_a665c5df :
PS5, Line 6247: if (strcmp(p[1], "*") != 0)
should we issue a warning if someone specifies "--local *" without port number that this is a NOOP?

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/c0b1d821_0f10076d :
PS5, Line 358: options
either this should use "l" or the definition of "l" should be removed completely.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 5
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: its_Giaan <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 16 Oct 2024 14:06:07 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#9 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.

its_Giaan has uploaded a new patch set (#6) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

allow user to specify 'local' multiple times in config files

It is now possible to specify 'local' multiple times in a server config to let it listen on multiple sockets (address:port) of the same protocol.

Change-Id I4d1c96662c5a8c750d883e3b20adde09529e2764

---
M doc/man-sections/link-options.rst
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c

5 files changed, 179 insertions(+), 46 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/436/6

doc/man-sections/link-options.rst +7 -5
index ca192c3..d519539 100644
@@ -106,13 +106,15 @@
   is not reliable. It is recommended to set tun-mtu with enough headroom
   instead.
 
---local host
-  Local host name or IP address for bind. If specified, OpenVPN will bind
-  to this address only. If unspecified, OpenVPN will bind to all
-  interfaces.
+--local host|* [port]
+  Local host name or IP address and port for bind. If specified, OpenVPN will bind
+  to this address. If unspecified, OpenVPN will bind to all interfaces.
+  '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
+  is returned by the OS). Implies --bind, 0.0.0.0 or :: can be used to specifically
+  open a socket.
 
 --lport port
-  Set local TCP/UDP port number or name. Cannot be used together with
+  Set default TCP/UDP port number. Cannot be used together with
   ``--nobind`` option.
 
 --mark value
src/openvpn/init.c +2 -1
index b246cce..3b9dc35 100644
@@ -742,7 +742,7 @@
 
     init_connection_list(c);
 
-    c->c1.link_sockets_num = 1;
+    c->c1.link_sockets_num = c->options.ce.local_list->len;
 
     do_link_socket_addr_new(c);
 
@@ -4962,6 +4962,7 @@
     if (dest->mode == CM_CHILD_UDP)
     {
         ASSERT(!dest->c2.link_sockets);
+        ASSERT(dest->options.ce.local_list);
 
         /* inherit buffers */
         dest->c2.buffers = src->c2.buffers;
src/openvpn/options.c +139 -28

253 lines not on this page · raw message

src/openvpn/options.h +14 -1
index ee39dbb..6942455 100644
@@ -94,14 +94,21 @@
 #error "At least one of OpenSSL or mbed TLS needs to be defined."
 #endif
 
+struct local_entry
+{
+    const char *local;
+    const char *port;
+    bool bind_local;
+};
+
 struct connection_entry
 {
+    struct local_list *local_list;
     int proto;
     sa_family_t af;
     const char *local_port;
     bool local_port_defined;
     const char *remote_port;
-    const char *local;
     const char *remote;
     bool remote_float;
     bool bind_defined;
@@ -179,6 +186,12 @@
 
 #define CONNECTION_LIST_SIZE 64
 
+struct local_list
+{
+    int len;
+    struct local_entry *array[CONNECTION_LIST_SIZE];
+};
+
 struct connection_list
 {
     int capacity;
src/openvpn/socket.c +17 -11
index 2b55021..67c8f06 100644
@@ -342,7 +342,6 @@
 void
 do_preresolve(struct context *c)
 {
-    int i;
     struct connection_list *l = c->options.connection_list;
     const unsigned int preresolve_flags = GETADDR_RESOLVE
                                           |GETADDR_UPDATE_MANAGEMENT_STATE
@@ -350,13 +349,13 @@
                                           |GETADDR_FATAL;
 
 
-    for (i = 0; i < l->len; ++i)
+    for (int i = 0; i < l->len; ++i)
     {
         int status;
         const char *remote;
         int flags = preresolve_flags;
 
-        struct connection_entry *ce = c->options.connection_list->array[i];
+        struct connection_entry *ce = l->array[i];
 
         if (proto_is_dgram(ce->proto))
         {
@@ -416,12 +415,19 @@
             }
         }
 
-        if (ce->bind_local)
+        flags |= GETADDR_PASSIVE;
+        flags &= ~GETADDR_RANDOMIZE;
+
+        for (int j = 0; j < ce->local_list->len; j++)
         {
-            flags |= GETADDR_PASSIVE;
-            flags &= ~GETADDR_RANDOMIZE;
-            status = do_preresolve_host(c, ce->local, ce->local_port,
-                                        ce->af, flags);
+            struct local_entry *le = ce->local_list->array[j];
+
+            if (!le->local)
+            {
+                continue;
+            }
+
+            status = do_preresolve_host(c, le->local, le->port, ce->af, flags);
             if (status != 0)
             {
                 goto err;
@@ -1863,14 +1869,14 @@
 {
     ASSERT(c->c2.link_sockets[sock_index]);
 
-    c->c2.link_sockets[sock_index]->local_host = c->options.ce.local;
-    c->c2.link_sockets[sock_index]->local_port = c->options.ce.local_port;
+    c->c2.link_sockets[sock_index]->local_host = c->options.ce.local_list->array[sock_index]->local;
+    c->c2.link_sockets[sock_index]->local_port = c->options.ce.local_list->array[sock_index]->port;
     c->c2.link_sockets[sock_index]->remote_host = c->options.ce.remote;
     c->c2.link_sockets[sock_index]->remote_port = c->options.ce.remote_port;
     c->c2.link_sockets[sock_index]->dns_cache = c->c1.dns_cache;
     c->c2.link_sockets[sock_index]->http_proxy = c->c1.http_proxy;
     c->c2.link_sockets[sock_index]->socks_proxy = c->c1.socks_proxy;
-    c->c2.link_sockets[sock_index]->bind_local = c->options.ce.bind_local;
+    c->c2.link_sockets[sock_index]->bind_local = c->options.ce.local_list->array[sock_index]->bind_local;
     c->c2.link_sockets[sock_index]->resolve_retry_seconds = c->options.resolve_retry_seconds;
     c->c2.link_sockets[sock_index]->mtu_discover_type = c->options.ce.mtu_discover_type;
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 6
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset

#10 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, ordex, plaisthos.

its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Patch Set 6:

(6 comments)

File doc/man-sections/link-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/e41c0651_4dde7880 :
PS5, Line 114: 0.0.0.0 or :: can be used to specifically open a socket.

Quoted 1 line

Sentence does end in the middle?

Done

http://gerrit.openvpn.net/c/openvpn/+/436/comment/5a0ba867_50a05ad8 :
PS5, Line 117: or name

Quoted 1 line

Should probably say "default TCP/UDP port number" or something like that and mention that this can b […]

Done

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/bea38f19_4d89f447 :
PS5, Line 2400: * Sanity check on daemon mode

Quoted 1 line

Not sure what daemon is supposed to mean in this context?

Done

http://gerrit.openvpn.net/c/openvpn/+/436/comment/a4fc0da7_d28cb303 :
PS5, Line 3198: if (ce->proto == PROTO_UDP && ce->socks_proxy_server && !ce->local_list && !ce->local_port_defined && !ce->bind_defined)

Quoted 1 line

Should use need_bind to simplify the condition.

Done

http://gerrit.openvpn.net/c/openvpn/+/436/comment/08d0b545_36ce02f5 :
PS5, Line 3327: options_postprocess_mutate_le(struct options *o, struct local_entry *le)

Quoted 1 line

should maybe take o->ce as input and not o, just to make clear that it doesn't need the rest?

Done

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/f094b608_24a1894e :
PS5, Line 358: options

Quoted 1 line

either this should use "l" or the definition of "l" should be removed completely.

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 6
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Thu, 17 Oct 2024 14:50:31 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment

#11 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Patch Set 7: Code-Review-1

(9 comments)

Patchset:

PS7:
This is messier than it should be - having the local list in the CE structure, while it is only useful for servers (that do not use CE). But maybe this cannot be fixed if we do want to permit a (single) local entry inside a <connection> (which makes sense).

But besides this, there's questions...

File doc/man-sections/link-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/2ee16be6_972b5621 :
PS7, Line 114: open a socket.
This text is not clear to me. What does "*" do? (This interacts with #761 on ::).

Maybe:

```
On a client, or in point-to-point mode, this can only be specified once (1 socket).  On an OpenVPN setup running as `--server`, this can be specified multiple times to open multiple listening sockets on different addresses and/or different ports.

In order to specify multiple listen ports without specifying an address, use '*' to signal "use what the operating system gives you as default".  For "all IPv4 addresses" use '0.0.0.0', for "all IPv6 addresses" use '::'.

`--local` implies `--bind`.
```

(It's also slightly unclear how this interacts with --proto? Maybe this is added in a later patch of the series?)

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/c96e1fb3_88b2e29c :
PS7, Line 133: " a server listen on multiple sockets at the same time.\n"
when there is agreement on the wording in the manpage, this needs to be addressed as well

http://gerrit.openvpn.net/c/openvpn/+/436/comment/1ff60b54_20cb34b1 :
PS7, Line 998: setenv_str_i(es, "local", e->local_list->array[0]->local, i);
will this crash if --local has not been used at all?

http://gerrit.openvpn.net/c/openvpn/+/436/comment/24119bb9_af8f4bf9 :
PS7, Line 2406: }
I would not check on ce->remote but on mode == SERVER here, and change the wording to multiple --local statements only allowed in --server mode.

Also, will this crash if no --local statement has been used (aka is the list always initialized?)

http://gerrit.openvpn.net/c/openvpn/+/436/comment/8fdc0098_59259f5f :
PS7, Line 3185: bool need_bind = ce->local_port_defined || ce->bind_defined;
this looks incomplete - shouldn't the existence of a --local entry also set need_bind = true?

http://gerrit.openvpn.net/c/openvpn/+/436/comment/f467c398_a6c43f2d :
PS7, Line 3198: if (o->client && !need_bind)
is this intentional or a rebase artefact? This looks a bit unrelated

http://gerrit.openvpn.net/c/openvpn/+/436/comment/18bf97b8_6adc2bc6 :
PS7, Line 3827: /* use the same listen list for every outgoing connection */
well... for outgoing connections we do not want to use a *list* at all, as we can only bind() once...? (but I need to read up on o->ce vs. o->connection_list)

http://gerrit.openvpn.net/c/openvpn/+/436/comment/42fa7611_2d03d61e :
PS7, Line 6250: e->bind_local = true;
I do not understand this bind_local variable. Of course we bind(), otherwise the whole setting of local does not make sense? And even on "*" we do want to bind()...?

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 7
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 27 Nov 2024 18:19:55 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#12 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, its_Giaan, ordex, plaisthos.

its_Giaan has uploaded a new patch set (#8) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

The following approvals got outdated and were removed:
Code-Review-1 by cron2

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

allow user to specify 'local' multiple times in config files

It is now possible to specify 'local' multiple times in a server config to let it listen on multiple sockets (address:port) of the same protocol.

Change-Id I4d1c96662c5a8c750d883e3b20adde09529e2764

---
M doc/man-sections/link-options.rst
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c

5 files changed, 183 insertions(+), 45 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/436/8

doc/man-sections/link-options.rst +17 -5
index ca192c3..8eb2b65 100644
@@ -106,13 +106,25 @@
   is not reliable. It is recommended to set tun-mtu with enough headroom
   instead.
 
---local host
-  Local host name or IP address for bind. If specified, OpenVPN will bind
-  to this address only. If unspecified, OpenVPN will bind to all
-  interfaces.
+--local host|* [port]
+  Local host name or IP address and port for bind. If specified, OpenVPN will bind
+  to this address. If unspecified, OpenVPN will bind to all interfaces.
+  '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
+  is returned by the OS).
+  On a client, or in point-to-point mode, this can only be specified once (1 socket).
+  On an OpenVPN setup running as ``--server``, this can be specified multiple times
+  to open multiple listening sockets on different addresses and/or different ports.
+  In order to specify multiple listen ports without specifying an address, use '*'
+  to signal "use what the operating system gives you as default", for
+  "all IPv4 addresses" use "0.0.0.0", for "all IPv6 addresses" use '::'.
+  ``--local`` implies ``--bind``.
+
+
+  Implies --bind, 0.0.0.0 or :: can be used to specifically
+  open a socket.
 
 --lport port
-  Set local TCP/UDP port number or name. Cannot be used together with
+  Set default TCP/UDP port number. Cannot be used together with
   ``--nobind`` option.
 
 --mark value
src/openvpn/init.c +2 -1
index 2cc37df..7923d57 100644
@@ -743,7 +743,7 @@
 
     init_connection_list(c);
 
-    c->c1.link_sockets_num = 1;
+    c->c1.link_sockets_num = c->options.ce.local_list->len;
 
     do_link_socket_addr_new(c);
 
@@ -4976,6 +4976,7 @@
     if (dest->mode == CM_CHILD_UDP)
     {
         ASSERT(!dest->c2.link_sockets);
+        ASSERT(dest->options.ce.local_list);
 
         /* inherit buffers */
         dest->c2.buffers = src->c2.buffers;
src/openvpn/options.c +135 -28

243 lines not on this page · raw message

src/openvpn/options.h +13 -1
index 6ab92e2..008f7cf 100644
@@ -94,14 +94,20 @@
 #error "At least one of OpenSSL or mbed TLS needs to be defined."
 #endif
 
+struct local_entry
+{
+    const char *local;
+    const char *port;
+};
+
 struct connection_entry
 {
+    struct local_list *local_list;
     int proto;
     sa_family_t af;
     const char *local_port;
     bool local_port_defined;
     const char *remote_port;
-    const char *local;
     const char *remote;
     bool remote_float;
     bool bind_defined;
@@ -179,6 +185,12 @@
 
 #define CONNECTION_LIST_SIZE 64
 
+struct local_list
+{
+    int len;
+    struct local_entry *array[CONNECTION_LIST_SIZE];
+};
+
 struct connection_list
 {
     int capacity;
src/openvpn/socket.c +16 -10
index cb7da51..7921433 100644
@@ -342,7 +342,6 @@
 void
 do_preresolve(struct context *c)
 {
-    int i;
     struct connection_list *l = c->options.connection_list;
     const unsigned int preresolve_flags = GETADDR_RESOLVE
                                           |GETADDR_UPDATE_MANAGEMENT_STATE
@@ -350,13 +349,13 @@
                                           |GETADDR_FATAL;
 
 
-    for (i = 0; i < l->len; ++i)
+    for (int i = 0; i < l->len; ++i)
     {
         int status;
         const char *remote;
         int flags = preresolve_flags;
 
-        struct connection_entry *ce = c->options.connection_list->array[i];
+        struct connection_entry *ce = l->array[i];
 
         if (proto_is_dgram(ce->proto))
         {
@@ -416,12 +415,19 @@
             }
         }
 
-        if (ce->bind_local)
+        flags |= GETADDR_PASSIVE;
+        flags &= ~GETADDR_RANDOMIZE;
+
+        for (int j = 0; j < ce->local_list->len; j++)
         {
-            flags |= GETADDR_PASSIVE;
-            flags &= ~GETADDR_RANDOMIZE;
-            status = do_preresolve_host(c, ce->local, ce->local_port,
-                                        ce->af, flags);
+            struct local_entry *le = ce->local_list->array[j];
+
+            if (!le->local)
+            {
+                continue;
+            }
+
+            status = do_preresolve_host(c, le->local, le->port, ce->af, flags);
             if (status != 0)
             {
                 goto err;
@@ -1865,8 +1871,8 @@
     struct options *o = &c->options;
     ASSERT(sock);
 
-    sock->local_host = o->ce.local;
-    sock->local_port = o->ce.local_port;
+    sock->local_host = o->ce.local_list->array[sock_index]->local;
+    sock->local_port = o->ce.local_list->array[sock_index]->port;
     sock->remote_host = o->ce.remote;
     sock->remote_port = o->ce.remote_port;
     sock->dns_cache = c->c1.dns_cache;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 8
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset

#13 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, ordex, plaisthos.

its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Patch Set 8:

(9 comments)

File doc/man-sections/link-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/8dd8c81c_1c28df37 :
PS7, Line 114: open a socket.

Quoted 1 line

This text is not clear to me. What does "*" do? (This interacts with #761 on ::). […]

Done, for the text.

(--proto)
It will not interact with --proto, I tried to avoid checking it as it is fishy on the server side since we may have multiple sockets of different protocols, instead we will check the protocol for each socket when possible, otherwise we rely on the mode.

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/3c4e7f07_331b4f56 :
PS5, Line 6247: if (strcmp(p[1], "*") != 0)

Quoted 1 line

should we issue a warning if someone specifies "--local *" without port number that this is a NOOP?

Acknowledged

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/d9af2a74_f67140b0 :
PS7, Line 133: " a server listen on multiple sockets at the same time.\n"

Quoted 1 line

when there is agreement on the wording in the manpage, this needs to be addressed as well

Done

http://gerrit.openvpn.net/c/openvpn/+/436/comment/b04415ed_9d0e4ae8 :
PS7, Line 998: setenv_str_i(es, "local", e->local_list->array[0]->local, i);

Quoted 1 line

will this crash if --local has not been used at all?

No, it will not, even without specifying any '--local' we're gonna create a local_entry based on the global port, see options.c:3818 for details.

http://gerrit.openvpn.net/c/openvpn/+/436/comment/750168cd_967ca0a0 :
PS7, Line 2406: }

Quoted 1 line

I would not check on ce->remote but on mode == SERVER here, and change the wording to `multiple […]

Done for the check.

See answer above for --local crash question.

http://gerrit.openvpn.net/c/openvpn/+/436/comment/fb946320_525f1ec3 :
PS7, Line 3185: bool need_bind = ce->local_port_defined || ce->bind_defined;

Quoted 1 line

this looks incomplete - shouldn't the existence of a --local entry also set need_bind = true?

Extended this with checking for the local_list, (if not NULL we're going to bind).

http://gerrit.openvpn.net/c/openvpn/+/436/comment/d52d560f_2dcb23ff :
PS7, Line 3198: if (o->client && !need_bind)

Quoted 1 line

is this intentional or a rebase artefact? This looks a bit unrelated

Done

http://gerrit.openvpn.net/c/openvpn/+/436/comment/6ecec3d0_fc5af621 :
PS7, Line 3827: /* use the same listen list for every outgoing connection */

Quoted 1 line

well... for outgoing connections we do not want to use a *list* at all, as we can only bind() once.. […]

We handle everything as a list, but later on there's a specific sanity check that in the case of clients ensures that the list has only one element.

http://gerrit.openvpn.net/c/openvpn/+/436/comment/3a5e4b2a_9eed652f :
PS7, Line 6250: e->bind_local = true;

Quoted 1 line

I do not understand this bind_local variable. […]

I removed the bind_local variable on the local_entry and rely on the o->ce.bind_local which has all the sanity checks of the case.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 8
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Thu, 12 Dec 2024 09:42:51 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment

#14 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, ordex, plaisthos.

its_Giaan has uploaded a new patch set (#10) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

allow user to specify 'local' multiple times in config files

It is now possible to specify 'local' multiple times in a server config to let it listen on multiple sockets (address:port) of the same protocol.

Change-Id I4d1c96662c5a8c750d883e3b20adde09529e2764

---
M doc/man-sections/link-options.rst
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c

5 files changed, 183 insertions(+), 45 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/436/10

doc/man-sections/link-options.rst +17 -5
index ca192c3..8eb2b65 100644
@@ -106,13 +106,25 @@
   is not reliable. It is recommended to set tun-mtu with enough headroom
   instead.
 
---local host
-  Local host name or IP address for bind. If specified, OpenVPN will bind
-  to this address only. If unspecified, OpenVPN will bind to all
-  interfaces.
+--local host|* [port]
+  Local host name or IP address and port for bind. If specified, OpenVPN will bind
+  to this address. If unspecified, OpenVPN will bind to all interfaces.
+  '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
+  is returned by the OS).
+  On a client, or in point-to-point mode, this can only be specified once (1 socket).
+  On an OpenVPN setup running as ``--server``, this can be specified multiple times
+  to open multiple listening sockets on different addresses and/or different ports.
+  In order to specify multiple listen ports without specifying an address, use '*'
+  to signal "use what the operating system gives you as default", for
+  "all IPv4 addresses" use "0.0.0.0", for "all IPv6 addresses" use '::'.
+  ``--local`` implies ``--bind``.
+
+
+  Implies --bind, 0.0.0.0 or :: can be used to specifically
+  open a socket.
 
 --lport port
-  Set local TCP/UDP port number or name. Cannot be used together with
+  Set default TCP/UDP port number. Cannot be used together with
   ``--nobind`` option.
 
 --mark value
src/openvpn/init.c +2 -1
index 850cd12..86378f7 100644
@@ -751,7 +751,7 @@
 
     init_connection_list(c);
 
-    c->c1.link_sockets_num = 1;
+    c->c1.link_sockets_num = c->options.ce.local_list->len;
 
     do_link_socket_addr_new(c);
 
@@ -4981,6 +4981,7 @@
     if (dest->mode == CM_CHILD_UDP)
     {
         ASSERT(!dest->c2.link_sockets);
+        ASSERT(dest->options.ce.local_list);
 
         /* inherit buffers */
         dest->c2.buffers = src->c2.buffers;
src/openvpn/options.c +135 -28

243 lines not on this page · raw message

src/openvpn/options.h +13 -1
index 6ab92e2..008f7cf 100644
@@ -94,14 +94,20 @@
 #error "At least one of OpenSSL or mbed TLS needs to be defined."
 #endif
 
+struct local_entry
+{
+    const char *local;
+    const char *port;
+};
+
 struct connection_entry
 {
+    struct local_list *local_list;
     int proto;
     sa_family_t af;
     const char *local_port;
     bool local_port_defined;
     const char *remote_port;
-    const char *local;
     const char *remote;
     bool remote_float;
     bool bind_defined;
@@ -179,6 +185,12 @@
 
 #define CONNECTION_LIST_SIZE 64
 
+struct local_list
+{
+    int len;
+    struct local_entry *array[CONNECTION_LIST_SIZE];
+};
+
 struct connection_list
 {
     int capacity;
src/openvpn/socket.c +16 -10
index 0e9e4f8..6112332 100644
@@ -342,7 +342,6 @@
 void
 do_preresolve(struct context *c)
 {
-    int i;
     struct connection_list *l = c->options.connection_list;
     const unsigned int preresolve_flags = GETADDR_RESOLVE
                                           |GETADDR_UPDATE_MANAGEMENT_STATE
@@ -350,13 +349,13 @@
                                           |GETADDR_FATAL;
 
 
-    for (i = 0; i < l->len; ++i)
+    for (int i = 0; i < l->len; ++i)
     {
         int status;
         const char *remote;
         int flags = preresolve_flags;
 
-        struct connection_entry *ce = c->options.connection_list->array[i];
+        struct connection_entry *ce = l->array[i];
 
         if (proto_is_dgram(ce->proto))
         {
@@ -416,12 +415,19 @@
             }
         }
 
-        if (ce->bind_local)
+        flags |= GETADDR_PASSIVE;
+        flags &= ~GETADDR_RANDOMIZE;
+
+        for (int j = 0; j < ce->local_list->len; j++)
         {
-            flags |= GETADDR_PASSIVE;
-            flags &= ~GETADDR_RANDOMIZE;
-            status = do_preresolve_host(c, ce->local, ce->local_port,
-                                        ce->af, flags);
+            struct local_entry *le = ce->local_list->array[j];
+
+            if (!le->local)
+            {
+                continue;
+            }
+
+            status = do_preresolve_host(c, le->local, le->port, ce->af, flags);
             if (status != 0)
             {
                 goto err;
@@ -1882,8 +1888,8 @@
     const char *remote_host = o->ce.remote;
     const char *remote_port = o->ce.remote_port;
 
-    sock->local_host = o->ce.local;
-    sock->local_port = o->ce.local_port;
+    sock->local_host = o->ce.local_list->array[sock_index]->local;
+    sock->local_port = o->ce.local_list->array[sock_index]->port;
     sock->remote_host = remote_host;
     sock->remote_port = remote_port;
     sock->dns_cache = c->c1.dns_cache;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 10
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset

#15 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Patch Set 10:

(3 comments)

File doc/man-sections/link-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/2e09fad4_f8cd789d :
PS7, Line 114: open a socket.

Quoted 1 line

Done, for the text. […]

Done

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/0fb1fac6_8c60bfdc :
PS7, Line 3827: /* use the same listen list for every outgoing connection */

Quoted 1 line

We handle everything as a list, but later on there's a specific sanity check that in the case of cli […]

Done

http://gerrit.openvpn.net/c/openvpn/+/436/comment/843e9fd5_709eae74 :
PS7, Line 6250: e->bind_local = true;

Quoted 1 line

I removed the bind_local variable on the local_entry and rely on the o->ce. […]

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 10
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Mon, 30 Dec 2024 17:42:11 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: its_Giaan <[email protected]...>
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment

#16 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Patch Set 10: Code-Review-1

(4 comments)

Patchset:

PS10:
This works, but I find the local_list structure in need of improvement.

File src/openvpn/options.h:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/b51da7c8_0ec98e70 :
PS10, Line 105: struct local_list *local_list;
I do not like this data structure - having an extra indirection seems to serve no good purpose (like, it's not actually a "list").

All the other new multisocket code just has a local array, and I think we should do the same thing here - that is:

`struct connection_entry

{
    struct local_entry *local_list;
    int local_list_len;
    ...

`

most of the remaining code will simplify itself (ce->local_list->array[i] to ce->local_list[i] etc.) or will not care at all (if dealing with a le).

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/b6ab664e_ab058053 :
PS10, Line 2476: msg(M_USAGE, "--remote and a --local addresses are the same");
a local address, singular :-) (or one of the --local addresses)

Dunno. Something grammarly correct :-)

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/fc6cd992_13935a2b :
PS10, Line 421: for (int j = 0; j < ce->local_list->len; j++)
is this save against "no --local specified at all, list not initialized"? The old code had an if (ce->bind_local) check here, for which I'm missing the equivalent

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 10
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Mon, 30 Dec 2024 19:04:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#17 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, its_Giaan, plaisthos.

ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Patch Set 10:

(1 comment)

File src/openvpn/options.h:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/6b965d3f_513428fb :
PS10, Line 105: struct local_list *local_list;

Quoted 1 line

I do not like this data structure - having an extra indirection seems to serve no good purpose (like […]

Gianmarco dived north and south to remove this local_list container. However, he found the actual reason for having a pointer to a container here, instead of the plain array: the value of struct local_list * is copied over all connection entries, so that the list of locals can be shared.

If we remove such container and let a struct connection_entry directly have a local_list[] member, we then need to copy this array over to every other connection entry.

Hence, we use more memory and we must memcpy() the array to every ce.

Would you agree that it may be better to keep the local_list container as it is now and avoid this complexity?

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 10
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 08 Jan 2025 15:21:08 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment

#18 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Patch Set 10:

(1 comment)

File src/openvpn/options.h:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/64b2e454_7dc2ac24 :
PS10, Line 105: struct local_list *local_list;

Quoted 1 line

Gianmarco dived north and south to remove this local_list container. […]

You're not supposed to have a local_list[] member but a struct local_entry *... which can be copied around as you want.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 10
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 08 Jan 2025 16:12:43 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment

#19 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Patch Set 10: -Code-Review

(1 comment)

File src/openvpn/options.h:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/aae7f902_0402e836 :
PS10, Line 105: struct local_list *local_list;

Quoted 1 line

You're not supposed to have a local_list[] member but a struct local_entry *... […]

okay, so we discussed this at lenght in IRC. There are other xxx_list things with array[] elements (well, ** array, and dynamic allocations, but that's an incremental improvelemts). So I withdraw my objection "we don't do this elsewhere", and with the copying around it's easier to always have the len automatic.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 10
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Thu, 09 Jan 2025 08:38:17 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment

#20 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.

its_Giaan has uploaded a new patch set (#11) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

allow user to specify 'local' multiple times in config files

It is now possible to specify 'local' multiple times in a server config to let it listen on multiple sockets (address:port) of the same protocol.

Change-Id I4d1c96662c5a8c750d883e3b20adde09529e2764

---
M doc/man-sections/link-options.rst
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c

5 files changed, 187 insertions(+), 46 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/436/11

doc/man-sections/link-options.rst +17 -5
index ca192c3..8eb2b65 100644
@@ -106,13 +106,25 @@
   is not reliable. It is recommended to set tun-mtu with enough headroom
   instead.
 
---local host
-  Local host name or IP address for bind. If specified, OpenVPN will bind
-  to this address only. If unspecified, OpenVPN will bind to all
-  interfaces.
+--local host|* [port]
+  Local host name or IP address and port for bind. If specified, OpenVPN will bind
+  to this address. If unspecified, OpenVPN will bind to all interfaces.
+  '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
+  is returned by the OS).
+  On a client, or in point-to-point mode, this can only be specified once (1 socket).
+  On an OpenVPN setup running as ``--server``, this can be specified multiple times
+  to open multiple listening sockets on different addresses and/or different ports.
+  In order to specify multiple listen ports without specifying an address, use '*'
+  to signal "use what the operating system gives you as default", for
+  "all IPv4 addresses" use "0.0.0.0", for "all IPv6 addresses" use '::'.
+  ``--local`` implies ``--bind``.
+
+
+  Implies --bind, 0.0.0.0 or :: can be used to specifically
+  open a socket.
 
 --lport port
-  Set local TCP/UDP port number or name. Cannot be used together with
+  Set default TCP/UDP port number. Cannot be used together with
   ``--nobind`` option.
 
 --mark value
src/openvpn/init.c +2 -1
index 2bd5518..b5630da 100644
@@ -751,7 +751,7 @@
 
     init_connection_list(c);
 
-    c->c1.link_sockets_num = 1;
+    c->c1.link_sockets_num = c->options.ce.local_list->len;
 
     do_link_socket_addr_new(c);
 
@@ -4978,6 +4978,7 @@
     if (dest->mode == CM_CHILD_UDP)
     {
         ASSERT(!dest->c2.link_sockets);
+        ASSERT(dest->options.ce.local_list);
 
         /* inherit buffers */
         dest->c2.buffers = src->c2.buffers;
src/openvpn/options.c +135 -28

243 lines not on this page · raw message

src/openvpn/options.h +13 -1
index 55f12dd..3f4cb90 100644
@@ -94,14 +94,20 @@
 #error "At least one of OpenSSL or mbed TLS needs to be defined."
 #endif
 
+struct local_entry
+{
+    const char *local;
+    const char *port;
+};
+
 struct connection_entry
 {
+    struct local_list *local_list;
     int proto;
     sa_family_t af;
     const char *local_port;
     bool local_port_defined;
     const char *remote_port;
-    const char *local;
     const char *remote;
     bool remote_float;
     bool bind_defined;
@@ -179,6 +185,12 @@
 
 #define CONNECTION_LIST_SIZE 64
 
+struct local_list
+{
+    int len;
+    struct local_entry *array[CONNECTION_LIST_SIZE];
+};
+
 struct connection_list
 {
     int capacity;
src/openvpn/socket.c +20 -11
index 0e9e4f8..2d45109 100644
@@ -342,7 +342,6 @@
 void
 do_preresolve(struct context *c)
 {
-    int i;
     struct connection_list *l = c->options.connection_list;
     const unsigned int preresolve_flags = GETADDR_RESOLVE
                                           |GETADDR_UPDATE_MANAGEMENT_STATE
@@ -350,13 +349,13 @@
                                           |GETADDR_FATAL;
 
 
-    for (i = 0; i < l->len; ++i)
+    for (int i = 0; i < l->len; ++i)
     {
         int status;
         const char *remote;
         int flags = preresolve_flags;
 
-        struct connection_entry *ce = c->options.connection_list->array[i];
+        struct connection_entry *ce = l->array[i];
 
         if (proto_is_dgram(ce->proto))
         {
@@ -420,13 +419,23 @@
         {
             flags |= GETADDR_PASSIVE;
             flags &= ~GETADDR_RANDOMIZE;
-            status = do_preresolve_host(c, ce->local, ce->local_port,
-                                        ce->af, flags);
-            if (status != 0)
-            {
-                goto err;
-            }
 
+            for (int j = 0; j < ce->local_list->len; j++)
+            {
+                struct local_entry *le = ce->local_list->array[j];
+
+                if (!le->local)
+                {
+                    continue;
+                }
+
+                status = do_preresolve_host(c, le->local, le->port, ce->af, flags);
+                if (status != 0)
+                {
+                    goto err;
+                }
+
+            }
         }
 
     }
@@ -1882,8 +1891,8 @@
     const char *remote_host = o->ce.remote;
     const char *remote_port = o->ce.remote_port;
 
-    sock->local_host = o->ce.local;
-    sock->local_port = o->ce.local_port;
+    sock->local_host = o->ce.local_list->array[sock_index]->local;
+    sock->local_port = o->ce.local_list->array[sock_index]->port;
     sock->remote_host = remote_host;
     sock->remote_port = remote_port;
     sock->dns_cache = c->c1.dns_cache;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 11
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset

#21 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, ordex, plaisthos.

its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Patch Set 11:

(2 comments)

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/9783668c_48b6cdb6 :
PS10, Line 2476: msg(M_USAGE, "--remote and a --local addresses are the same");

Quoted 1 line

a local address, singular :-) (or one of the --local addresses) […]

Done

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/9530a00a_45891312 :
PS10, Line 421: for (int j = 0; j < ce->local_list->len; j++)

Quoted 1 line

is this save against "no --local specified at all, list not initialized"? The old code had an `if […]

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 11
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Thu, 09 Jan 2025 13:47:18 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment

#22 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Patch Set 11:

(4 comments)

Patchset:

PS11:
A few comments to look at, but at this point I'd say "fix the manpage and ship" ;-)

File doc/man-sections/link-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/5e7f4c84_d49c3a9f :
PS11, Line 124: open a socket.
As discussed on IRC, this is still a bit unclear / a leftover from earlier versions.

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/87b58fcf_5e96bec6 :
PS11, Line 2485: if (le->local && !ce->bind_local)
I do wonder if we really need to check this for every entry in the local_list, or checking it once (if ( ce->local_list && !ce->bind_local )) would be sufficient... but this is not really important.

http://gerrit.openvpn.net/c/openvpn/+/436/comment/9744ee88_ecea7af7 :
PS11, Line 3780: options_postprocess_mutate_le(o->ce, o->ce.local_list->array[i]);
I guess that this is preparations for one of the later patches? For the simple case having an extra function 420 lines further up in the code seems more complicated then necessary.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 11
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Thu, 23 Jan 2025 15:22:20 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

#23 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.

its_Giaan has uploaded a new patch set (#12) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

allow user to specify 'local' multiple times in config files

It is now possible to specify 'local' multiple times in a server config to let it listen on multiple sockets (address:port) of the same protocol.

Change-Id I4d1c96662c5a8c750d883e3b20adde09529e2764

---
M doc/man-sections/link-options.rst
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c

5 files changed, 184 insertions(+), 46 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/436/12

doc/man-sections/link-options.rst +14 -5
index ca192c3..2667b93 100644
@@ -106,13 +106,22 @@
   is not reliable. It is recommended to set tun-mtu with enough headroom
   instead.
 
---local host
-  Local host name or IP address for bind. If specified, OpenVPN will bind
-  to this address only. If unspecified, OpenVPN will bind to all
-  interfaces.
+--local host|* [port]
+  Local host name or IP address and port for bind. If specified, OpenVPN will bind
+  to this address. If unspecified, OpenVPN will bind to all interfaces.
+  '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
+  is returned by the OS).
+  On a client, or in point-to-point mode, this can only be specified once (1 socket).
+
+  On an OpenVPN setup running as ``--server``, this can be specified multiple times
+  to open multiple listening sockets on different addresses and/or different ports.
+  In order to specify multiple listen ports without specifying an address, use '*'
+  to signal "use what the operating system gives you as default", for
+  "all IPv4 addresses" use "0.0.0.0", for "all IPv6 addresses" use '::'.
+  ``--local`` implies ``--bind``.
 
 --lport port
-  Set local TCP/UDP port number or name. Cannot be used together with
+  Set default TCP/UDP port number. Cannot be used together with
   ``--nobind`` option.
 
 --mark value
src/openvpn/init.c +2 -1
index 9d1048c..4014517 100644
@@ -751,7 +751,7 @@
 
     init_connection_list(c);
 
-    c->c1.link_sockets_num = 1;
+    c->c1.link_sockets_num = c->options.ce.local_list->len;
 
     do_link_socket_addr_new(c);
 
@@ -4978,6 +4978,7 @@
     if (dest->mode == CM_CHILD_UDP)
     {
         ASSERT(!dest->c2.link_sockets);
+        ASSERT(dest->options.ce.local_list);
 
         /* inherit buffers */
         dest->c2.buffers = src->c2.buffers;
src/openvpn/options.c +135 -28

243 lines not on this page · raw message

src/openvpn/options.h +13 -1
index 55f12dd..3f4cb90 100644
@@ -94,14 +94,20 @@
 #error "At least one of OpenSSL or mbed TLS needs to be defined."
 #endif
 
+struct local_entry
+{
+    const char *local;
+    const char *port;
+};
+
 struct connection_entry
 {
+    struct local_list *local_list;
     int proto;
     sa_family_t af;
     const char *local_port;
     bool local_port_defined;
     const char *remote_port;
-    const char *local;
     const char *remote;
     bool remote_float;
     bool bind_defined;
@@ -179,6 +185,12 @@
 
 #define CONNECTION_LIST_SIZE 64
 
+struct local_list
+{
+    int len;
+    struct local_entry *array[CONNECTION_LIST_SIZE];
+};
+
 struct connection_list
 {
     int capacity;
src/openvpn/socket.c +20 -11
index 0c4a7bc..97dce02 100644
@@ -342,7 +342,6 @@
 void
 do_preresolve(struct context *c)
 {
-    int i;
     struct connection_list *l = c->options.connection_list;
     const unsigned int preresolve_flags = GETADDR_RESOLVE
                                           |GETADDR_UPDATE_MANAGEMENT_STATE
@@ -350,13 +349,13 @@
                                           |GETADDR_FATAL;
 
 
-    for (i = 0; i < l->len; ++i)
+    for (int i = 0; i < l->len; ++i)
     {
         int status;
         const char *remote;
         int flags = preresolve_flags;
 
-        struct connection_entry *ce = c->options.connection_list->array[i];
+        struct connection_entry *ce = l->array[i];
 
         if (proto_is_dgram(ce->proto))
         {
@@ -420,13 +419,23 @@
         {
             flags |= GETADDR_PASSIVE;
             flags &= ~GETADDR_RANDOMIZE;
-            status = do_preresolve_host(c, ce->local, ce->local_port,
-                                        ce->af, flags);
-            if (status != 0)
-            {
-                goto err;
-            }
 
+            for (int j = 0; j < ce->local_list->len; j++)
+            {
+                struct local_entry *le = ce->local_list->array[j];
+
+                if (!le->local)
+                {
+                    continue;
+                }
+
+                status = do_preresolve_host(c, le->local, le->port, ce->af, flags);
+                if (status != 0)
+                {
+                    goto err;
+                }
+
+            }
         }
 
     }
@@ -1882,8 +1891,8 @@
     const char *remote_host = o->ce.remote;
     const char *remote_port = o->ce.remote_port;
 
-    sock->local_host = o->ce.local;
-    sock->local_port = o->ce.local_port;
+    sock->local_host = o->ce.local_list->array[sock_index]->local;
+    sock->local_port = o->ce.local_list->array[sock_index]->port;
     sock->remote_host = remote_host;
     sock->remote_port = remote_port;
     sock->dns_cache = c->c1.dns_cache;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 12
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset

#24 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

Patch Set 12: Code-Review+2

(2 comments)

Patchset:

PS12:
I think we need to do some more wordsmithing (possibly find a native speaker that understands OpenVPN...) here, but for now, this should go on.

File doc/man-sections/link-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/436/comment/7c571c01_7328cf09 :
PS11, Line 124: open a socket.

Quoted 1 line

As discussed on IRC, this is still a bit unclear / a leftover from earlier versions.

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 12
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Thu, 23 Jan 2025 15:50:49 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment

#25 lore raw

PATCH v12 1/1 allow user to specify 'local' multiple times in config files

In reply to a message not in the archive

From: Antonio Quartulli <[email protected]...>

It is now possible to specify 'local' multiple times in a server config to let it listen on multiple sockets (address:port) of the same protocol.

Change-Id I4d1c96662c5a8c750d883e3b20adde09529e2764

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/436
This mail reflects revision 12 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

doc/man-sections/link-options.rst +14 -5
index ca192c3..2667b93 100644
@@ -106,13 +106,22 @@
   is not reliable. It is recommended to set tun-mtu with enough headroom
   instead.
 
---local host
-  Local host name or IP address for bind. If specified, OpenVPN will bind
-  to this address only. If unspecified, OpenVPN will bind to all
-  interfaces.
+--local host|* [port]
+  Local host name or IP address and port for bind. If specified, OpenVPN will bind
+  to this address. If unspecified, OpenVPN will bind to all interfaces.
+  '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
+  is returned by the OS). 
+  On a client, or in point-to-point mode, this can only be specified once (1 socket).
+  
+  On an OpenVPN setup running as ``--server``, this can be specified multiple times
+  to open multiple listening sockets on different addresses and/or different ports.
+  In order to specify multiple listen ports without specifying an address, use '*'
+  to signal "use what the operating system gives you as default", for
+  "all IPv4 addresses" use "0.0.0.0", for "all IPv6 addresses" use '::'.
+  ``--local`` implies ``--bind``.
 
 --lport port
-  Set local TCP/UDP port number or name. Cannot be used together with
+  Set default TCP/UDP port number. Cannot be used together with
   ``--nobind`` option.
 
 --mark value
src/openvpn/init.c +2 -1
index 9d1048c..4014517 100644
@@ -751,7 +751,7 @@
 
     init_connection_list(c);
 
-    c->c1.link_sockets_num = 1;
+    c->c1.link_sockets_num = c->options.ce.local_list->len;
 
     do_link_socket_addr_new(c);
 
@@ -4978,6 +4978,7 @@
     if (dest->mode == CM_CHILD_UDP)
     {
         ASSERT(!dest->c2.link_sockets);
+        ASSERT(dest->options.ce.local_list);
 
         /* inherit buffers */
         dest->c2.buffers = src->c2.buffers;
src/openvpn/options.c +135 -28

243 lines not on this page · raw message

src/openvpn/options.h +13 -1
index 55f12dd..3f4cb90 100644
@@ -94,14 +94,20 @@
 #error "At least one of OpenSSL or mbed TLS needs to be defined."
 #endif
 
+struct local_entry
+{
+    const char *local;
+    const char *port;
+};
+
 struct connection_entry
 {
+    struct local_list *local_list;
     int proto;
     sa_family_t af;
     const char *local_port;
     bool local_port_defined;
     const char *remote_port;
-    const char *local;
     const char *remote;
     bool remote_float;
     bool bind_defined;
@@ -179,6 +185,12 @@
 
 #define CONNECTION_LIST_SIZE 64
 
+struct local_list
+{
+    int len;
+    struct local_entry *array[CONNECTION_LIST_SIZE];
+};
+
 struct connection_list
 {
     int capacity;
src/openvpn/socket.c +20 -11
index 0c4a7bc..97dce02 100644
@@ -342,7 +342,6 @@
 void
 do_preresolve(struct context *c)
 {
-    int i;
     struct connection_list *l = c->options.connection_list;
     const unsigned int preresolve_flags = GETADDR_RESOLVE
                                           |GETADDR_UPDATE_MANAGEMENT_STATE
@@ -350,13 +349,13 @@
                                           |GETADDR_FATAL;
 
 
-    for (i = 0; i < l->len; ++i)
+    for (int i = 0; i < l->len; ++i)
     {
         int status;
         const char *remote;
         int flags = preresolve_flags;
 
-        struct connection_entry *ce = c->options.connection_list->array[i];
+        struct connection_entry *ce = l->array[i];
 
         if (proto_is_dgram(ce->proto))
         {
@@ -420,13 +419,23 @@
         {
             flags |= GETADDR_PASSIVE;
             flags &= ~GETADDR_RANDOMIZE;
-            status = do_preresolve_host(c, ce->local, ce->local_port,
-                                        ce->af, flags);
-            if (status != 0)
-            {
-                goto err;
-            }
 
+            for (int j = 0; j < ce->local_list->len; j++)
+            {
+                struct local_entry *le = ce->local_list->array[j];
+
+                if (!le->local)
+                {
+                    continue;
+                }
+
+                status = do_preresolve_host(c, le->local, le->port, ce->af, flags);
+                if (status != 0)
+                {
+                    goto err;
+                }
+
+            }
         }
 
     }
@@ -1882,8 +1891,8 @@
     const char *remote_host = o->ce.remote;
     const char *remote_port = o->ce.remote_port;
 
-    sock->local_host = o->ce.local;
-    sock->local_port = o->ce.local_port;
+    sock->local_host = o->ce.local_list->array[sock_index]->local;
+    sock->local_port = o->ce.local_list->array[sock_index]->port;
     sock->remote_host = remote_host;
     sock->remote_port = remote_port;
     sock->dns_cache = c->c1.dns_cache;
#26 lore raw

[Openvpn-devel] [PATCH applied] Re: allow user to specify 'local' multiple times in config files

This is a patch that isn't actually *doing* anything so far, because it's just bringing infrastructure. So I stared quite hard at the code, and subjected it to the usual client/server tests (to ensure it does not accidentially break anything). With this patch, doing multiple '--local' will actually produce multiple bound sockets...

udp        0      0 0.0.0.0:21104           0.0.0.0:*                          
udp6       0      0 :::21106                :::*                               
udp6       0      0 :::31194                :::*                               

("local 0.0.0.0 21104" + "local :: 21106" + "local * 21106" on FreeBSD)

but it will not add all of these to the event handler, so it's not working correctly - the first bound socket does work, the rest not (just as a word of warning).

Testing for real begin with one of the next patches that actually introduces "add all to the event loop".

Your patch has been applied to the master branch.

commit 8466c2ca3faf0dc143262ea2a76bfe3e2aff9f51

Author: Antonio Quartulli
Date:   Thu Jan 23 16:51:11 2025 +0100
     allow user to specify 'local' multiple times in config files

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Signed-off-by: Gianmarco De Gregori <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg30544.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#27 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#13) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

allow user to specify 'local' multiple times in config files

It is now possible to specify 'local' multiple times in a server config to let it listen on multiple sockets (address:port) of the same protocol.

Change-Id I4d1c96662c5a8c750d883e3b20adde09529e2764

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30544.html

---
M doc/man-sections/link-options.rst
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c

5 files changed, 184 insertions(+), 46 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/436/13

doc/man-sections/link-options.rst +14 -5
index ca192c3..4496da2 100644
@@ -106,13 +106,22 @@
   is not reliable. It is recommended to set tun-mtu with enough headroom
   instead.
 
---local host
-  Local host name or IP address for bind. If specified, OpenVPN will bind
-  to this address only. If unspecified, OpenVPN will bind to all
-  interfaces.
+--local host|* [port]
+  Local host name or IP address and port for bind. If specified, OpenVPN will bind
+  to this address. If unspecified, OpenVPN will bind to all interfaces.
+  '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
+  is returned by the OS).
+  On a client, or in point-to-point mode, this can only be specified once (1 socket).
+
+  On an OpenVPN setup running as ``--server``, this can be specified multiple times
+  to open multiple listening sockets on different addresses and/or different ports.
+  In order to specify multiple listen ports without specifying an address, use '*'
+  to signal "use what the operating system gives you as default", for
+  "all IPv4 addresses" use "0.0.0.0", for "all IPv6 addresses" use '::'.
+  ``--local`` implies ``--bind``.
 
 --lport port
-  Set local TCP/UDP port number or name. Cannot be used together with
+  Set default TCP/UDP port number. Cannot be used together with
   ``--nobind`` option.
 
 --mark value
src/openvpn/init.c +2 -1
index 9d1048c..4014517 100644
@@ -751,7 +751,7 @@
 
     init_connection_list(c);
 
-    c->c1.link_sockets_num = 1;
+    c->c1.link_sockets_num = c->options.ce.local_list->len;
 
     do_link_socket_addr_new(c);
 
@@ -4978,6 +4978,7 @@
     if (dest->mode == CM_CHILD_UDP)
     {
         ASSERT(!dest->c2.link_sockets);
+        ASSERT(dest->options.ce.local_list);
 
         /* inherit buffers */
         dest->c2.buffers = src->c2.buffers;
src/openvpn/options.c +135 -28

243 lines not on this page · raw message

src/openvpn/options.h +13 -1
index 55f12dd..3f4cb90 100644
@@ -94,14 +94,20 @@
 #error "At least one of OpenSSL or mbed TLS needs to be defined."
 #endif
 
+struct local_entry
+{
+    const char *local;
+    const char *port;
+};
+
 struct connection_entry
 {
+    struct local_list *local_list;
     int proto;
     sa_family_t af;
     const char *local_port;
     bool local_port_defined;
     const char *remote_port;
-    const char *local;
     const char *remote;
     bool remote_float;
     bool bind_defined;
@@ -179,6 +185,12 @@
 
 #define CONNECTION_LIST_SIZE 64
 
+struct local_list
+{
+    int len;
+    struct local_entry *array[CONNECTION_LIST_SIZE];
+};
+
 struct connection_list
 {
     int capacity;
src/openvpn/socket.c +20 -11
index 7765372..d01b995 100644
@@ -342,7 +342,6 @@
 void
 do_preresolve(struct context *c)
 {
-    int i;
     struct connection_list *l = c->options.connection_list;
     const unsigned int preresolve_flags = GETADDR_RESOLVE
                                           |GETADDR_UPDATE_MANAGEMENT_STATE
@@ -350,13 +349,13 @@
                                           |GETADDR_FATAL;
 
 
-    for (i = 0; i < l->len; ++i)
+    for (int i = 0; i < l->len; ++i)
     {
         int status;
         const char *remote;
         int flags = preresolve_flags;
 
-        struct connection_entry *ce = c->options.connection_list->array[i];
+        struct connection_entry *ce = l->array[i];
 
         if (proto_is_dgram(ce->proto))
         {
@@ -420,13 +419,23 @@
         {
             flags |= GETADDR_PASSIVE;
             flags &= ~GETADDR_RANDOMIZE;
-            status = do_preresolve_host(c, ce->local, ce->local_port,
-                                        ce->af, flags);
-            if (status != 0)
-            {
-                goto err;
-            }
 
+            for (int j = 0; j < ce->local_list->len; j++)
+            {
+                struct local_entry *le = ce->local_list->array[j];
+
+                if (!le->local)
+                {
+                    continue;
+                }
+
+                status = do_preresolve_host(c, le->local, le->port, ce->af, flags);
+                if (status != 0)
+                {
+                    goto err;
+                }
+
+            }
         }
 
     }
@@ -1874,8 +1883,8 @@
     const char *remote_host = o->ce.remote;
     const char *remote_port = o->ce.remote_port;
 
-    sock->local_host = o->ce.local;
-    sock->local_port = o->ce.local_port;
+    sock->local_host = o->ce.local_list->array[sock_index]->local;
+    sock->local_port = o->ce.local_list->array[sock_index]->port;
     sock->remote_host = remote_host;
     sock->remote_port = remote_port;
     sock->dns_cache = c->c1.dns_cache;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 13
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#28 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/436?usp=email )

Change subject: allow user to specify 'local' multiple times in config files
......................................................................

allow user to specify 'local' multiple times in config files

It is now possible to specify 'local' multiple times in a server config to let it listen on multiple sockets (address:port) of the same protocol.

Change-Id I4d1c96662c5a8c750d883e3b20adde09529e2764

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30544.html

---
M doc/man-sections/link-options.rst
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c

5 files changed, 184 insertions(+), 46 deletions(-)
doc/man-sections/link-options.rst +14 -5
index ca192c3..4496da2 100644
@@ -106,13 +106,22 @@
   is not reliable. It is recommended to set tun-mtu with enough headroom
   instead.
 
---local host
-  Local host name or IP address for bind. If specified, OpenVPN will bind
-  to this address only. If unspecified, OpenVPN will bind to all
-  interfaces.
+--local host|* [port]
+  Local host name or IP address and port for bind. If specified, OpenVPN will bind
+  to this address. If unspecified, OpenVPN will bind to all interfaces.
+  '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
+  is returned by the OS).
+  On a client, or in point-to-point mode, this can only be specified once (1 socket).
+
+  On an OpenVPN setup running as ``--server``, this can be specified multiple times
+  to open multiple listening sockets on different addresses and/or different ports.
+  In order to specify multiple listen ports without specifying an address, use '*'
+  to signal "use what the operating system gives you as default", for
+  "all IPv4 addresses" use "0.0.0.0", for "all IPv6 addresses" use '::'.
+  ``--local`` implies ``--bind``.
 
 --lport port
-  Set local TCP/UDP port number or name. Cannot be used together with
+  Set default TCP/UDP port number. Cannot be used together with
   ``--nobind`` option.
 
 --mark value
src/openvpn/init.c +2 -1
index 9d1048c..4014517 100644
@@ -751,7 +751,7 @@
 
     init_connection_list(c);
 
-    c->c1.link_sockets_num = 1;
+    c->c1.link_sockets_num = c->options.ce.local_list->len;
 
     do_link_socket_addr_new(c);
 
@@ -4978,6 +4978,7 @@
     if (dest->mode == CM_CHILD_UDP)
     {
         ASSERT(!dest->c2.link_sockets);
+        ASSERT(dest->options.ce.local_list);
 
         /* inherit buffers */
         dest->c2.buffers = src->c2.buffers;
src/openvpn/options.c +135 -28

243 lines not on this page · raw message

src/openvpn/options.h +13 -1
index 55f12dd..3f4cb90 100644
@@ -94,14 +94,20 @@
 #error "At least one of OpenSSL or mbed TLS needs to be defined."
 #endif
 
+struct local_entry
+{
+    const char *local;
+    const char *port;
+};
+
 struct connection_entry
 {
+    struct local_list *local_list;
     int proto;
     sa_family_t af;
     const char *local_port;
     bool local_port_defined;
     const char *remote_port;
-    const char *local;
     const char *remote;
     bool remote_float;
     bool bind_defined;
@@ -179,6 +185,12 @@
 
 #define CONNECTION_LIST_SIZE 64
 
+struct local_list
+{
+    int len;
+    struct local_entry *array[CONNECTION_LIST_SIZE];
+};
+
 struct connection_list
 {
     int capacity;
src/openvpn/socket.c +20 -11
index 7765372..d01b995 100644
@@ -342,7 +342,6 @@
 void
 do_preresolve(struct context *c)
 {
-    int i;
     struct connection_list *l = c->options.connection_list;
     const unsigned int preresolve_flags = GETADDR_RESOLVE
                                           |GETADDR_UPDATE_MANAGEMENT_STATE
@@ -350,13 +349,13 @@
                                           |GETADDR_FATAL;
 
 
-    for (i = 0; i < l->len; ++i)
+    for (int i = 0; i < l->len; ++i)
     {
         int status;
         const char *remote;
         int flags = preresolve_flags;
 
-        struct connection_entry *ce = c->options.connection_list->array[i];
+        struct connection_entry *ce = l->array[i];
 
         if (proto_is_dgram(ce->proto))
         {
@@ -420,13 +419,23 @@
         {
             flags |= GETADDR_PASSIVE;
             flags &= ~GETADDR_RANDOMIZE;
-            status = do_preresolve_host(c, ce->local, ce->local_port,
-                                        ce->af, flags);
-            if (status != 0)
-            {
-                goto err;
-            }
 
+            for (int j = 0; j < ce->local_list->len; j++)
+            {
+                struct local_entry *le = ce->local_list->array[j];
+
+                if (!le->local)
+                {
+                    continue;
+                }
+
+                status = do_preresolve_host(c, le->local, le->port, ce->af, flags);
+                if (status != 0)
+                {
+                    goto err;
+                }
+
+            }
         }
 
     }
@@ -1874,8 +1883,8 @@
     const char *remote_host = o->ce.remote;
     const char *remote_port = o->ce.remote_port;
 
-    sock->local_host = o->ce.local;
-    sock->local_port = o->ce.local_port;
+    sock->local_host = o->ce.local_list->array[sock_index]->local;
+    sock->local_port = o->ce.local_list->array[sock_index]->port;
     sock->remote_host = remote_host;
     sock->remote_port = remote_port;
     sock->dns_cache = c->c1.dns_cache;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 13
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged